#include<stdio.h>
#include<stdlib.h>

int* masterMind(char* solution, char* guess, int* returnSize);

int main()
{
    char* solution = "BRBB";
    char* guess = "RBGY";
    
    int returnSize;
    int *ret = masterMind(solution, guess, &returnSize);
    
    printf("%d %d", ret[0], ret[1]);
    
    free(ret);
    
    return 0;
} 

int* masterMind(char* solution, char* guess, int* returnSize) {
    *returnSize = 2;
    int* ret = malloc(sizeof(int) * 2);
    int realguess = 0, fakeguess = 0, totalguess = 0;
    
    int i, j;
    for(i = 0; i < 4; i++)
    {
        if(solution[i] == guess[i])
        {
            realguess++;
        }
    }

    int frequentOfsolution[4] = {0};
    int frequentOfguess[4] = {0};

    for(i = 0; i < 4; i++)
    {
        if(solution[i] == 'R')
        {
            frequentOfsolution[0] ++;
        }
        if(solution[i] == 'G')
        {
            frequentOfsolution[1] ++;
        }
        if(solution[i] == 'B')
        {
            frequentOfsolution[2] ++;
        }
        if(solution[i] == 'Y')
        {
            frequentOfsolution[3] ++;
        }
    }

    for(i = 0; i < 4; i++)
    {
        if(guess[i] == 'R')
        {
            frequentOfguess[0] ++;
        }
        if(guess[i] == 'G')
        {
            frequentOfguess[1] ++;
        }
        if(guess[i] == 'B')
        {
            frequentOfguess[2] ++;
        }
        if(guess[i] == 'Y')
        {
            frequentOfguess[3] ++;
        }
    }

    for(i = 0; i < 4; i++)
    {
        if(frequentOfsolution[i] && frequentOfguess[i])
        {
            if(frequentOfsolution[i] == frequentOfguess[i])
            {
                totalguess += frequentOfsolution[i];
                continue;
            }
            if(frequentOfsolution[i] > frequentOfguess[i])
            {
                totalguess += frequentOfguess[i];
                continue;
            }
            if(frequentOfsolution[i] < frequentOfguess[i])
            {
                totalguess += frequentOfsolution[i];
                continue;
            }
            totalguess++;
        }
    }

    fakeguess = totalguess- realguess;

    ret[0] = realguess;
    ret[1] = fakeguess;

    return ret;
}

